/*
 * Copyright (c) 2005, The haXe Project Contributors
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

 
package hxphp.oo.gd;

import hxphp.oo.gd.GDImage;

class GDText 
{
	public var resource:GDResource;
	
	public function new(resource:GDResource) 
	{
		this.resource = resource;
	}

	
	/** Load a new font */
	public function loadFont ( file:String ):Int
	{
		return untyped __call__("imageloadfont", file);
	}
	
	/** Returns the pixel height of a character in the specified font. */
	public function fontHeight (font_index:Int):Int
	{
		return untyped __call__("imagefontheight", font_index);
	}
	
	/** Returns the pixel width of a character in font.  */
	public function fontWidth (font_index:Int):Int
	{
		return untyped __call__("imagefontwidth", font_index);
	}
	
	/** draws the first character of c in the image identified by image with its upper-left at x,y (top left is 0, 0) with the color color. If font is 1, 2, 3, 4 or 5, a built-in font is used (with higher numbers corresponding to larger fonts). */
	public function char ( font_index:Int, x:Int, y:Int, c:String, color:Int ):Bool 
	{
		return untyped __call__("imagechar", resource, font_index, x, y, c, color);
	}
	
	/** draws the character c vertically in the image identified by image at coordinates x, y (top left is 0, 0) with the color color */
	public function charUp ( font_index:Int, x:Int, y:Int, c:String, color:Int )
	{
		return untyped __call__("imagecharup", resource, font_index, x, y, c, color);
	}
	
	/** Draw a string horizontally  */
	public function write ( font_index:Int, x:Int, y:Int, s:String, col:Int ):Bool
	{
		return untyped __call__("imagestring", resource, font_index, x, y, s, col );
	}
	
	/** Draw a string vertically */
	public function writeUp ( font_index:Int, x:Int, y:Int, s:String, col:Int ):Bool
	{
		return untyped __call__("imagestringup", resource, font_index, x, y, s, col );
	}
	
	/** To draw a text string over an image using PostScript Type1 fonts  */
	public function writePSText ( text:String, font:GDPostscriptFont, size:Int, foreground:Int, background:Int, x:Int, y:Int, ?space:Int, ?tightness:Int, ?angle:Float, ?antialias_steps:Int )
	{
		return untyped __call__("imagepstext", resource, text, font.fontResource, size, foreground, background, x, y, space, tightness, angle, antialias_steps );
	}
	
	
	
	// PS 1
	
	
	/** Load a PostScript Type 1 font from file  */
	public function loadPSFont ( filename:String ):GDPostscriptFont
	{
		return new GDPostscriptFont(filename);
	}
	
	
	
	// TrueType
	
	/** This function calculates and returns the bounding box in pixels for a TrueType text.   */
	public function TTFBBox( size:Float, angle:Float, fontfile:String, text:String ):Array<Dynamic>
	{
		return untyped __call__("imagettfbbox", size, angle, fontfile, text);
	}
	
	/** Write text to the image using TrueType fonts  */
	public function TrueTypeText( size:Float, angle:Float, x:Int, y:Int, color:Int, fontfile:String, text:String ):Array<Dynamic>
	{
		return untyped __call__("imagettftext", resource, size, angle, x, y, color, fontfile, text);
	}
	
	
	
	// FreeType 2
	
	
	/** Write text to the image using fonts using FreeType 2  */
	public function FreeType2Text(size:Float, angle:Float, x:Int, y:Int, col:Int, font_file:String, text:String, ?extrainfo:Array<Dynamic> ):Array<Dynamic>
	{
		return untyped __call__("imagefttbox", resource, size, angle, x, y, col, font_file, text, extrainfo);
	}
	
	/** Give the bounding box of a text using fonts via freetype2 */
	public function FreeType2BBox (size:Float, angle:Float, font_file:String, text:String, ?extrainfo:Array<Dynamic> ):Array<Dynamic>	
	{
		return untyped __call__("imageftbbox", size, angle, font_file, text, extrainfo);
	}
	
}